<%@ Language=VBScript%>
<!--#include file="..\..\CheckSession.inc"-->
<!--#include file=..\..\jvGrid.inc-->
<!--#include file=..\..\jvFunction.inc-->
<!--#include file="..\..\RootContent.inc"-->
<!--#include file="..\..\getFormName.inc"-->
<%
	IDFlow=request("IDFlow")
	Nguoitao=request("Nguoitao")
	Filename=Request("Filename")
	UName=Request("Username")
	Hanxuly=Request("Hanxuly")
	MaCB=Request("MaCB")
	Tentep=Request("Tentep")
	Maflow=Request("Maflow")
	bMaRoot=Request("bMaRoot")
	Yeucau=Request("Yeucau")
	bDatao=Request("bDatao")
	Set ClsFun=server.CreateObject("Vinalines.ClsFunction")
	Backform=Request("Backform")+1
	'bMa=Request("bMa")
	bComm=Request("bComm")
	bdaxuly=Request("bdaxuly")
	if Request("bPost")="ok" then
		'Save Text		
		Path=RootContent & "Data\xuly\Text"
		Path=Path & "\" & ClsFun.Giaima(Maflow) & ".VT"
		Set TextFile=server.CreateObject("Vinalines.ClsFile")		
		TextFile.SaveFile Request("Body"),Path		
		Set TextFile=nothing
	end if	
	If bComm="remove" then
'		f="Data/Yeucau/"
		Items=request("Listbox")
		bLen=Len(ITems)
		i=1
		on error resume next
		Conn.BeginTrans
		Set File = Server.CreateObject("ActiveFile.File")
		Do while i<=bLen			
			It=mid(ITems,i,1)
			if It<>"," then
				Temp=Temp+It
			else						
				if bLen<>i then					
					sSQL="Select Tentep from flownode_tentep where maflownode = '"& ClsFun.Giaima(Maflow) &"' and Sothutu =" & Temp
					Set RecVB=server.CreateObject("ADODB.Recordset")
					RecVB.CursorType=3
					RecVB.CacheSize=5
					RecVB.Open sSQL,Conn				
					if RecVB.RecordCount then																					
						Path=RootContent & "Data\xuly"
						File.Name=Path & "\" & RecVB("Tentep")
						if File.Exists() then
							File.Delete()
						end if
					end if
					RecVB.Close
					Set RecVB=nothing
					sSQL="Delete from flownode_Tentep Where maflownode = '"& ClsFun.Giaima(Maflow) &"' and Sothutu =" & Temp
					Conn.Execute sSQL
					Temp=""
				end if
			end if
			if i=bLen then			
				if i=1 then
					sSQL="Select Tentep from flownode_Tentep where maflownode = '"& ClsFun.Giaima(Maflow) &"' and Sothutu =" & IT
				else
					sSQL="Select Tentep from flownode_Tentep where maflownode = '"& ClsFun.Giaima(Maflow) &"' and Sothutu =" & Temp				
				end if
				Set RecVB=server.CreateObject("ADODB.Recordset")
				RecVB.CursorType=3
				RecVB.CacheSize=5
				RecVB.Open sSQL,Conn
				if RecVB.RecordCount then							
					Path=RootContent & "Data\xuly"
					File.Name=Path & "\" & RecVB("Tentep")
					if File.Exists() then
						File.Delete()
					end if
				end if
				RecVB.Close
				Set RecVB=nothing
				sSQL="Delete from flownode_Tentep Where maflownode = '"& ClsFun.Giaima(Maflow) &"' and Sothutu =" & Temp
				Conn.Execute sSQL
			end if
			i=i+1
		Loop
		Set File=nothing
		if Err.number=0 then
			Conn.CommitTrans
		else
			Conn.RollbackTrans
		end if
	end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT LANGUAGE=javascript >
function frmupload_onsubmit()
{
	if (frmupload.UploadedFile.value=="")
		{
		alert("Bạn phải nhập đường dẫn !")
		frm.TxtMota.focus;
		return false;
		}
	else
		{
		UploadedFile_onfocus();
		return false;
		}
}
function frm_onsubmit()
{
	if (frm.TxtMota.value=="")
		{
		alert("Bạn phải mô tả nội dung");
		frm.CmdAttach.focus;
		return false;
		}
	else
		{
		CmdAttach_onclick();
		return false;
		}
}
function CmdBack_onclick() {
	frmupload.target="right";
	frmupload.action="frmedit.asp?Nguoitao="+"<%=Nguoitao%>"+"&bMaRoot="+"<%=bMaRoot%>"+"&Maflow="+"<%=Maflow%>"+"&IDFlow="+"<%=IDFlow%>"+"&bdaxuly="+"<%=bdaxuly%>"+"&yeucau="+"<%=yeucau%>"+"&Backform="+"<%=Backform%>"+"&bDatao="+"<%=bDatao%>"+"&Filename="+"<%=Filename%>"+"&UName="+"<%=UName%>"+"&Hanxuly="+"<%=Hanxuly%>"+"&MaCB="+"<%=MaCB%>"+"&Tentep="+"<%=Tentep%>";
	frmupload.submit();
}
function CmdAttach_onclick() {
	if(frmupload.UploadedFile.value==""){
		alert("Bạn cần phải chọn tệp");
		return false;
	}
	if(frm.TxtMota.value==""){
		alert("Cho biết mô tả nội dung");
		frm.TxtMota.focus();
		return false;
	}
	frmupload.target="right";
	frmupload.action="upload.asp?Nguoitao="+"<%=Nguoitao%>"+"&bMaRoot="+"<%=bMaRoot%>"+"&Maflow="+"<%=Maflow%>"+"&bMota="+frm.TxtMota.value+"&IDFlow="+"<%=IDFlow%>"+"&yeucau="+"<%=yeucau%>"+"&Backform="+"<%=Backform%>"+"&bDatao="+"<%=bDatao%>"+"&Filename="+"<%=Filename%>"+"&UName="+"<%=UName%>"+"&Hanxuly="+"<%=Hanxuly%>"+"&MaCB="+"<%=MaCB%>"+"&Tentep="+"<%=Tentep%>";
	frmupload.submit();
}	
function CmdRemove_onclick() {
	if(frm.ListBox.value==""){
		alert("Bạn cần phải chọn tệp loại bỏ");
		return false;
	}	
	frm.action="attach.asp?Nguoitao="+"<%=Nguoitao%>"+"&bMaRoot="+"<%=bMaRoot%>"+"&bComm=remove&Maflow="+"<%=Maflow%>"+"&IDFlow="+"<%=IDFlow%>"+"&yeucau="+"<%=yeucau%>"+"&Backform="+"<%=Backform%>"+"&Tentep="+"<%=Tentep%>"+"&Filename="+"<%=Filename%>"+"&UName="+"<%=UName%>"+"&Hanxuly="+"<%=Hanxuly%>"+"&MaCB="+"<%=MaCB%>"+"&bDatao="+"<%=bDatao%>";
	frm.submit();
}
</SCRIPT>
<SCRIPT LANGUAGE=vbscript >
sub UploadedFile_onfocus
	if frmupload.UploadedFile.value<>"" then
		k=1
		longpath =len(frmupload.UploadedFile.value)
		check=true
		while k<longpath and check
			bdau=instr(k,frmupload.UploadedFile.value,"\")
			if bdau > 0 then
				bcuoi=instr(bdau+1,frmupload.UploadedFile.value,"\")
				if bcuoi = 0 then
					frm.TxtMota.value=mid(frmupload.UploadedFile.value,bdau+1,longpath-bdau)
					check=false
				end if
			else
				'alert("Duong dan sai !")
				frm.TxtMota.value=""
				check=false
			end if
			k=bdau+1
		Wend
	else
	frm.TxtMota.value=""
	end if
end sub
sub CmdAttach_onfocus
	if trim(frm.TxtMota.value)="" then
		frm.TxtMota.value=""
	end if
end sub
</SCRIPT>
</head>
<body style="font-family: Arial" bgcolor="#F8F9D9">
<center>
<%
	if request("Msg")="cancel" then
%><p align=center><font color=red >L&#7895;i Attach File     
<%end if%>
<form name=frmupload method=post enctype="multipart/form-data" onsubmit="return frmupload_onsubmit()">
		<input type=hidden name=IDFlow value='<%=IDFlow%>'>
		<input type=hidden name=Nguoitao value='<%=Nguoitao%>'>
		<input type=hidden name=UserName value='<%=UName%>'>
		<input type=hidden name=Hanxuly value='<%=Hanxuly%>'>
		<input type=hidden name=MaCB value='<%=MaCB%>'>
		<input type=hidden name=Tentep value='<%=Tentep%>'>
		<input type=hidden name=Maflow value='<%=Maflow%>'>
		<input type=hidden name=bMaRoot value='<%=bMaRoot%>'>
		<input type=hidden name=Yeucau value='<%=Yeucau%>'>
		<input type=hidden name=bDatao value='<%=bDatao%>'>	
		<input type=hidden name=Filename value='<%=Filename%>'>	
		<table border="0" width="600" cellspacing="0" cellpadding="0" height="158" bgcolor="#BDD5D0" bordercolor="#111111" style="Font-family:arial;font-size:11pt;BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0">
		<TR>	     
			<TD width=610 colspan=3 bgcolor="#000080" height="19" width="530">     
	          <p align="center"><font color="#FFFFFF">Danh s&#225;ch t&#7879;p</font></p>     
	        </TD>     
		<tr>     
	    <td width="270" height="24" colspan="2">     
	      <p align="center">     
	          <input type="file" name="UploadedFile" style="width: 430; height: 23" size="20" ></p>     
	    </td>
	    </form>     
		<form name=frm method=post onsubmit="return frm_onsubmit()">
	    <td width="263" height="24">
	    </td>     
	  </tr>     
	  <tr>     
	    <td height="110" style="width:265"valign="top" align="center" rowspan="5" colspan="2">     
	        <p align="center">     
	    		<SELECT name=ListBox size=7 style="width:430;font-family:Arial" multiple>      
	    		<%	     
					Set Rec=server.CreateObject("ADODB.Recordset")     
					sSQL="Select * from flownode_Tentep where maflownode = '"& ClsFun.Giaima(Maflow) &"'"     
					Rec.CursorType=3     
					Rec.CacheSize=5     
					Rec.Open sSQL,Conn     
					STT=1     
					Do while Not Rec.EOF     
				%>     
						<option value=<%=Rec("Sothutu")%>><%=Rec("mota")%></option>     
				<%     
						Rec.MoveNext     
					Loop     
				%>     
			</SELECT></p>     
	    </td>     
		<td width="499" height="22">     
		</tr>
		<tr>
		<td width="499" height="22">     
	    <p align="center"><Input type=Button name=CmdAttach value="G&#7855;n t&#7879;p" style="family-font: Arial; width: 128; height: 23; font-family: Arial" LANGUAGE=javascript onclick ="return CmdAttach_onclick()">
	    </td>     
	  </tr>     
	  <tr>     
	    <td width="499" height="22">     
	    <p align="center"><Input type=Button name=CmdRemove value="Lo&#7841;i kh&#7887;i danh s&#225;ch" style="family-font: Arial; width: 128; height: 23; font-family: Arial" LANGUAGE=javascript onclick="return CmdRemove_onclick()">     
	    </td>     
	  </tr>     
	  <tr>     
	    <td width="499" height="22">     
	    <p align="center"><Input type=Button name=CmdBack value="Quay l&#7841;i" style="family-font: Arial; width: 128; height: 23; font-family: Arial" LANGUAGE=javascript onclick="return CmdBack_onclick()">
	    </td>     
	  </tr>     
	  <tr>     
	    <td width="499" height="22">     
	    </td>     
	  </tr>     
	  <tr>     
          <td height="25" nowrap vAlign="top" width="120"><center><font face="Arial">M&#244;     
            t&#7843; n&#7897;i dung</font></center></td>     
          <td height="25" vAlign="top" width="339">
          <input type ="text" name="TxtMota" size="46"  style="FONT-FAMILY: Arial"></td>
      </tr>         
	</table>     
</Form>
</center>     
<%     
	Conn.Close     
	Set Conn=nothing     
	Set ClsFun=nothing
%> </font>

</body>     
</html>